package com.some;

import java.util.Arrays;
import java.util.Scanner;

// https://blog.csdn.net/m0_64889206/article/details/126147684
public class YouKa02 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int N = sc.nextInt();

        int[] q = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            q[i] = sc.nextInt();

        }
        int[] b = new int[N + 5];
        int[] l = new int[N + 5];
        int[] r = new int[N + 5];

        Arrays.sort(q);

        for (int i = 1; i <= N; i++) {
            b[i] = Math.min(q[i], X - q[i]);
        }

        int maxi = b[1];
        for (int i = 2; i <= N; i++)
            if (maxi < b[i]) maxi = b[i];
        System.out.print(maxi + " ");

        int max1 = Math.max(q[N], X - q[1]);
        for (int i = 2; i < N; i++) {
            l[i] = X - q[i - 1];//往左碰撞，向右回
            r[i] = q[i + 1];//往右碰撞，向左回
        }

        r[1] = q[2] - q[1];//读入往右碰撞，向左回的最后一个小球，即原来序列里第一个小球
        l[N] = X - q[N - 1];//读入往左碰撞， 向右回的第一个小球，  即原来序列里最后一个小球

        int ma1 = l[0];
        for (int i = 2; i <= N; i++)
            if (l[i] > ma1) ma1 = l[i];
        int ma2 = r[0];
        for (int i = 2; i <= N; i++)
            if (r[i] > ma2) ma2 = r[i];
        System.out.println(Math.max(max1, Math.max(ma1, ma2)));
    }
}
